require('assets/css/common.less');

import Vue from 'vue';
import VueResource from 'vue-resource';

import '@tencent/wmu2/dist/wmu.css';
import '@tencent/wmu2/dist/wmu.less';
import {ToastPlugin,AlertPlugin,ConfirmPlugin} from 'wmu2';
import {WiiGrid,WiiGridItem,WiiCalendar,WiiInput,WiiTextarea,WiiButton,WiiUploader,WiiImage,WiiImageGroup,WiiPicker,WiiCityPicker,WiiPopup,WiiPopupPicker,WiiDatetimePicker,WiiShake,WiiTurntable,WiiScratchcard,WiiSlotmachine} from 'wmu2';

var components = [WiiGrid,WiiGridItem,WiiCalendar,WiiInput,WiiTextarea,WiiButton,WiiUploader,WiiImage,WiiImageGroup,WiiPicker,WiiCityPicker,WiiPopup,WiiPopupPicker,WiiDatetimePicker,WiiShake,WiiTurntable,WiiScratchcard,WiiSlotmachine];


components.map(component => {
    Vue.component(component.name, component);
});

Vue.use(ToastPlugin);
Vue.use(AlertPlugin);
Vue.use(ConfirmPlugin);

Vue.use(VueResource);

//解决click点击300毫秒延时问题
import FastClick from 'fastclick';
FastClick.attach(document.body);

function getAllDayInMonth(year, month) {
    let allDay = new Array();
    let day = new Date();
    day.setFullYear(year, month - 1, 1);
    let firstDayInweek = day.getDay() == 0 ? 7 : day.getDay();
    day.setFullYear(year, month, 0);
    let daysCount = day.getDate();
    let start = firstDayInweek - 1;
    let end = firstDayInweek + daysCount - 2;
    for (let i = 0; i < daysCount; i++) {
        allDay[firstDayInweek + i - 1] = i + 1;
    }
    day.setFullYear(year, month - 1, 0);
    let preDaysCount = day.getDate();
    for (let i = firstDayInweek - 1; i > 0; i--) {
        allDay[i - 1] = preDaysCount - (firstDayInweek - (i + 1));
    }
    for (let i = daysCount + firstDayInweek; i < 6 * 7 + 1; i++) {
        allDay[i - 1] = i - (daysCount + firstDayInweek) + 1;
    }
    let allDay_list = new Array();
    for (let i = 0; i < 6; i++) {
        let item = new Array();
        for (let j = 0; j < 7; j++) {
            item[j] = {
                value: allDay[i * 7 + j],
                selected: false
            }
        }
        allDay_list.push(item)
    }
    return {
        allDay_list, start, end, year, month
    };
}

function dateFormat(date, fmt) {
    var o = {
        "M+": date.getMonth() + 1,
        "d+": date.getDate()
    };
    if (/(y+)/.test(fmt))
        fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
        if (new RegExp("(" + k + ")").test(fmt))
            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
}

window.getAllDayInMonth = getAllDayInMonth;
window.dateFormat = dateFormat;
